<template>
  <el-row type="flex" style="width: 100%">
    <el-col>{{ treeNode.name }}</el-col>
    <el-col :span="4">
      <el-row type="flex">
        <el-col>{{ treeNode.manager }}</el-col>
        <el-col>
          <el-dropdown>
            <span class="el-dropdown-link">
              操作
              <i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addDep">添加子部门</el-dropdown-item>
              <template v-if="!isRoot">
                <el-dropdown-item @click.native="editDep">编辑部门</el-dropdown-item>
                <el-dropdown-item @click.native="delDep">删除部门</el-dropdown-item>
              </template>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartment } from '@/api/department'
export default {
    props: {
        treeNode: {
            type: Object,
            required: true
        },
        isRoot: {
            type: Boolean,
            defalut: false
        }
    },
    methods: {
        delDep() {
            this.$confirm('亲亲你真的要删除嘛？').then(() => {
                return delDepartment(this.treeNode.id)
            }).then(() => {
                // 如果删除成功，就会执行这里
                this.$message.success('删除成功了哦~')
                this.$emit('updateDeps')
            })
        },
        addDep() {
            this.$emit('addDep', this.treeNode)
        },
        editDep() {
            this.$emit('editDep', this.treeNode)
        }
    }
};
</script>

<style>
</style>